package com.example.backend.exception;
import com.example.backend.common.ResultMessage;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.log4j.Log4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理器
 */
@ControllerAdvice
@Log4j
public class GlobalExceptionHandlerAdvice {

    @ExceptionHandler(Exception.class)    // 捕获所有异常
    @ResponseBody   // 返回json数据
    public ResultMessage handleException(Exception e, HttpServletRequest request, HttpServletResponse response) {
        log.info("系统代码错误："+e);
        return ResultMessage.error("系统代码错误");
    }





}
